package cn.lookup.controller;

import cn.lookup.domain.Role;
import cn.lookup.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/role")
public class RoleController {
    @Autowired
    @Qualifier("roleService")
    private RoleService roleService;
    @RequestMapping("/roleList")
    public ModelAndView roleList(ModelAndView modelAndView){
        List<Role> roleList = roleService.getRoleList();
        modelAndView.setViewName("role-list");
        modelAndView.addObject("roleList",roleList);
        return modelAndView;
    }
    @RequestMapping("/addRole")
    public String addRole(Role role){
        roleService.addRole(role);
        return "redirect:/role/roleList";
    }
    @RequestMapping("/deleteRole")
    public String deleteRole(Long roleId){
        roleService.deleteRole(roleId);
        return "redirect:/role/roleList";
    }


}
